﻿using SqlSugar;

namespace MyBlog.WebApi.ApiResult
{
    public class ApiResultsHelper
    {
        //只返回操作成功信息，状态码默认200
        public static ApiResults Success()
        {
            return new ApiResults
            {
                Code = 200,
                Msg = "操作成功",
                Data = null,
                Total = 0
            };
        }
        //默认200 自定义返回信息
        public static ApiResults Success(string msg)
        {
            return new ApiResults
            {
                Code = 200,
                Msg = msg,
                Data = null,
                Total = 0
            };
        }

        //默认200 自定义返回信息和返回数据
        public static ApiResults Success(string msg,dynamic data)
        {
            return new ApiResults
            {
                Code = 200,
                Msg = msg,
                Data = data,
                Total = 0
            };
        }
        //自定义状态码
        public static ApiResults Success(int code)
        {
            return new ApiResults
            {
                Code = code,
                Msg = "操作成功",
                Data = null,
                Total = 0
            };
        }

        //自定义状态码和message
        public static ApiResults Success(int code,string msg)
        {
            return new ApiResults
            {
                Code = code,
                Msg = msg,
                Data = null,
                Total = 0
            };
        }

        //自定义状态码、信息、返回数据
        public static ApiResults Success(int code,string msg, dynamic data)
        {
            return new ApiResults
            {
                Code = code,
                Msg = msg,
                Data = data,
                Total = 0
            };
        }

        //默认200状态码:执行成功后返回数据(分页版重载)
        public static ApiResults Success(dynamic data,RefAsync<int> total)
        {
            return new ApiResults
            {
                Code = 200,
                Msg = "操作成功",
                Data = data,
                Total = total
            };
        }


        //执行失败返回错误信息
        public static ApiResults Error(string msg)
        {
            return new ApiResults
            {
                Code = 500,
                Msg = msg,
                Data = null,
                Total = 0
            };
        }
        //执行失败返回错误信息
        public static ApiResults Error(int code, string msg)
        {
            return new ApiResults
            {
                Code = code,
                Msg = msg,
                Data = null,
                Total = 0
            };
        }

    }
}
